package dxc06;

import java.util.concurrent.ArrayBlockingQueue;

public class Foodie extends Thread {
    ArrayBlockingQueue<String> queue;

    public Foodie(ArrayBlockingQueue<String> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            //不断从阻塞队列中获取面条
            try {
                String food = queue.take();
                System.out.println("吃货吃掉了" + food);
                /*
                细节：我们在控制台看到的了连续的吃货或者厨师打印的语句，是因为打印语句写在了锁对象的外面导致的
                本质还是厨师放一个，吃货拿一个
                 */
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
